package com.koron.css2.clientCenter.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.MeterReaderBean;
import com.koron.css2.clientCenter.bean.ValveMessageBean;
import com.koron.css2.clientCenter.mapper.ValvePubMapper;
import com.koron.css2.clientCenter.mapper.ValveUserMapper;
import com.koron.css2.clientCenter.vo.ValveCloseListVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.springframework.beans.BeanUtils;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * @author cd
 * 添加-用户 关阀详情查询
 * 根据用户id list给出列表
 */
@Deprecated
public class ValveCloseDetailList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            List<String> idList = (List<String>) req.getData();

            ValvePubMapper pubMapper = factory.getMapper(ValvePubMapper.class);
            List<ValveMessageBean> messageList = pubMapper.getValveMessage();
            Map<String, ValveMessageBean> valveMap = messageList.stream().collect(Collectors.toMap(ValveMessageBean::getId, meterReaderBean -> meterReaderBean));


            ValveUserMapper userMapper = factory.getMapper(ValveUserMapper.class);
            List<MeterReaderBean> userList = userMapper.selectMeterReaderList(idList);
            Map<String, MeterReaderBean> userMap = userList.stream().collect(Collectors.toMap(MeterReaderBean::getUserNo, meterReaderBean -> meterReaderBean));


            List<ValveCloseListVo> voList = new ArrayList<>();
            for (MeterReaderBean meterReaderBean : userList) {
                ValveCloseListVo closeListVo = new ValveCloseListVo();
                BeanUtils.copyProperties(meterReaderBean, closeListVo);
                voList.add(closeListVo);
            }
            MessageBean<List> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", List.class);
            info.setData(voList);
            return info;
        } catch (Exception e) {
            logger.error("关阀管理列表查询失败" + e.getMessage(), e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
        }
    }
}
